<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<!-- 引入element样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>


<head>

    <footer th:fragment="table">
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">人员管理</div>
                            </div>
                            <div class="widget-body  am-fr">

                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-success" onclick="exportAdmin()"><span class="am-icon-plus"></span> 导出</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-danger" onclick="del()"><span class="am-icon-trash-o"></span> 删除</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-warning" data-toggle="modal" data-target="#addAdmins"><span class="am-icon-plus"></span> 添加</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{btnSize: 'sm'}" id="selectStatus" class="selectOption">
                                            <option value="" selected>请选择</option>
                                            <option value="1" th:selected="${status=='1'}">正常</option>
                                            <option value="0" th:selected="${status=='0'}">锁定</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field" id="adminName" th:value="${name}">
                                        <span class="am-input-group-btn">
                                         <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" th:onclick="selectAdmin()" type="button"></button>
                                    </span>
                                    </div>
                                </div>

                                <div class="am-u-sm-12">
                                    <div style="overflow-x:scroll">
                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                        <thead>
                                        <tr>
                                            <th><button onclick="reSelect()" class="am-btn  am-btn-default am-btn-success tpl-table-list-field" type="button">反选</button></th>
                                            <th>人员ID</th>
                                            <th>账号</th>
                                            <th>密码</th>
                                            <th>状态</th>
                                            <th>描述</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                            <tr class="gradeX" th:each="a : ${admin.list}">
                                                <td><input type="checkbox" name="persons" th:value="${a.adminId}"></td>
                                                <td th:text="${a.adminId}"></td>
                                                <td th:text="${a.adminAccount}"></td>
                                                <td th:text="${a.adminPassword}"></td>
                                                <td th:text="${a.adminStatus==0?'锁定':'正常'}"></td>
                                                <td>系统管理员</td>
                                                <td>
                                                    <div class="tpl-table-black-operation">

                                                        <a href="javascript:;" th:onclick="|updateStatus('${a.adminId}')|"  th:class="${a.adminStatus==1}?'tpl-table-black-operation-del':'tpl-table-black'">
                                                            <i class="am-icon-lock" th:text="${a.adminStatus==1?'锁定':'解锁'}"></i>
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    </div>
                                        <div class="am-u-lg-12 am-cf">
                                        <div class="am-u-lg-3">
                                            跳转至:<input type="number" id="pages" class="selectOption">/ 页
                                            <span>
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" th:onclick="gopages()"></button>
                                        </span>
                                        </div>


                                        <div class="am-fr">
                                            <ul class="am-pagination tpl-pagination">
                                                <li ><a href="javascript:" th:onclick="|gopage('${admin.navigateFirstPage}')|">首页</a></li>
                                                <li  th:if="admin.hasPreviousPage"><a href="javascript:" th:onclick="|gopage('${admin.prePage}')|">«</a></li>
                                                <li th:each="pageNum:${#numbers.sequence(1,admin.pages)}">
                                                    <a th:text="${pageNum}" th:onclick="|gopage('${pageNum}')|"></a>
                                                </li>
                                                <li th:if="admin.hasNextPage"><a href="javascript:" th:onclick="|gopage('${admin.nextPage}')|">»</a></li>
                                                <li><a href="javascript:" th:onclick="|gopage('${admin.navigateLastPage}')|">尾页</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <!--添加管理员信息模态框-->
            <div class="modal fade" id="addAdmins" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 300px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">添加管理员</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label for="inputName" class="control-label">账号:</label>
                                <input type="text" class="form-control" id="inputName" placeholder="Name">
                            </div>
                            <div class="form-group">
                                <label for="inputPassword" class="control-label">密码:</label>
                                <input type="password" class="form-control" id="inputPassword" placeholder="Password">
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" onclick="addAdmin()" >添加管理员</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>


        </div>
    </footer>
    <script>

        //条件查询
        function selectAdmin(){
            $.ajax({
                url:"/p2p/manage/getAllManage",
                data:{"name":$("#adminName").val(),"status":$("#selectStatus").val()},
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }


        //更新状态
        function updateStatus(i) {

            $.ajax({
                url:"/p2p/manage/changeStatus",
                data:{"adminId":i},
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }
        function exportAdmin() {
            alert("导出管理员")

        }


        //页面跳转
        function gopage(pageNum) {
            $.ajax({
                url:"/p2p/manage/getAllManage",
                data:{"name":$("#adminName").val(),"status":$("#selectStatus").val(),"pageNum":pageNum},
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        //输入框页面跳转
        function gopages() {

            $.ajax({
                url:"/p2p/manage/getAllManage",
                data:{"name":$("#adminName").val(),"status":$("#selectStatus").val(),"pageNum":$("#pages").val()},
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }
        //添加管理员
        function addAdmin() {
            $.ajax({
                url:"/p2p/manage/addAdmin",
                data:{"name":$("#inputName").val(),"pass":$("#inputPassword").val()},
                type:"post",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        //批量删除管理员
        function del() {
            var pros = $('input[name="persons"]:checked');

            if (pros.html() == undefined) {
                alert('请先选择人员')
                return;
            }
            var num = [];
            for (var i = 0; i < pros.length; i++) {
                var pro = pros.eq(i);
                pro.parent().parent().remove();//删除页面上对应的列
                num.push(pro.val());
            }
            $.ajax({
                url:"/p2p/manage/delAdmin",
                data:{"ids" : num.toString()},
                type:"post",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }


    </script>
</head>
</html>
